package com.wxx.controller.bg;

import com.wxx.model.DicRole;
import com.wxx.service.bg.DicRoleService;
import com.wxx.util.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/bg/dicRole/")
public class DicRoleController {

    @Autowired
    private DicRoleService dicRoleService;


    /**
     * 删除角色
     * @return
     */
    @RequestMapping(value = "del",method = RequestMethod.POST)
    @ResponseBody
    public Object del(Model model, String roleId){
        Map map = dicRoleService.del(roleId);
        return map;
    }

    /**
     * 跳转到编辑角色页面
     * @return
     */
    @RequestMapping(value = "toEdit",method = RequestMethod.GET)
    public String goEdit(Model model, String roleId){
        DicRole dicRole = dicRoleService.goEdit(roleId);
        model.addAttribute("model",dicRole);
        return "dicRole/edit";
    }

    /**
     * 编辑角色
     * @return
     */
    @RequestMapping(value = "edit",method = RequestMethod.POST)
    @ResponseBody
    public Object edit(Model model, DicRole dicRole){
        Map map = dicRoleService.edit(dicRole);
        return map;
    }

    /**
     * 跳转到添加角色页面
     * @return
     */
    @RequestMapping(value = "toAdd",method = RequestMethod.GET)
    public String toAdd(Model model){
        return "dicRole/add";
    }

    /**
     * 添加角色
     * @return
     */
    @RequestMapping(value = "add",method = RequestMethod.POST)
    @ResponseBody
    public Object add(Model model, DicRole dicRole){
        Map map = dicRoleService.add(dicRole);
        return map;
    }

    /**
     * 跳转到后台角色列表页面
     * @return
     */
    @RequestMapping(value = "toDicRoleList",method = RequestMethod.GET)
    public String toDicRoleList(){
        return "dicRole/list";
    }

    /**
     * 查询角色列表
     * @return
     */
    @RequestMapping(value = "findDicRoleList",method = RequestMethod.GET)
    @ResponseBody
    public Object findDicRoleList(){
        List<DicRole> dicRoleList = dicRoleService.findDicRoleList();
        return JsonData.returnLayuiMap(dicRoleList, dicRoleList.size());
    }

}
